package com.example.usercenter.utils;

import com.example.usercenter.pojo.Captcha;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class CaptchaUtil {

    public static int getCaptcha(String phoneNumber) throws Exception{

            OkHttpClient client = new OkHttpClient().newBuilder()
                    .build();
            MediaType mediaType = MediaType.parse("application/json");
//            RequestBody body = RequestBody.create(mediaType, "");
            Request request = new Request.Builder()
                    .url(BaseUrl.baseUrl+"/dev-api/sms/captchaNoReg?phoneNumber="+phoneNumber)
                    .get()
//                    .addHeader("Content-Type", "application/json")
                    .build();

            Response response = client.newCall(request).execute();
            String responseData = response.body().string();
            Gson gson = new Gson();
            Captcha captcha = gson.fromJson(responseData, Captcha.class);
            return captcha.getData();

    }
}
